package com.example.review.Fragment;


import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.example.review.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class GridViewFragment extends Fragment {
    @BindView(R.id.gridView)
    GridView gridView;
    @BindView(R.id.Rating)
    RatingBar rating;
    private View view;

    public GridViewFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_grid_view, container, false);
        ButterKnife.bind(this, view);
        initView();
        //设置评分条的最大范围
        rating.setMax(5);
        //设置星星数量
        rating.setNumStars(5);
        //设置当前等级
        rating.setRating(1);
        //设置步长
        rating.setStepSize(1);
        //获取星星数量
        int num = rating.getNumStars();
        return view;
    }

    private void initView() {
        String[] address = new String[]{"苏州·ACG大感谢祭"};
        String[] price = new String[]{"￥25起"};
        gridView.setAdapter(new myAdapter(address, price));
    }

    public class myAdapter extends BaseAdapter {
        String[] address;
        String[] price;

        public myAdapter(String[] address, String[] price) {
            this.address = address;
            this.price = price;
        }

        @Override
        public int getCount() {
            return 20;
        }

        @Override
        public Object getItem(int i) {
            return i;
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            if(gridView.getFirstVisiblePosition()==0){
                Log.v("TAG","eee");
            }
            else {
                Log.v("TAG","ddd");
            }
            ViewHolder holder;
            if (view == null) {
                view = LayoutInflater.from(getContext()).inflate(R.layout.layout_grid, viewGroup, false);
                holder = new ViewHolder(view);
                view.setTag(holder);
            } else {
                holder = (ViewHolder) view.getTag();
            }
            holder.address.setText(address[0]);
            holder.price.setText(price[0]);
            return view;
        }

        public class ViewHolder {
            @BindView(R.id.img_grid)
            ImageView imgGrid;
            @BindView(R.id.address)
            TextView address;
            @BindView(R.id.price)
            TextView price;
            @BindView(R.id.line_grid)
            LinearLayout lineGrid;

            ViewHolder(View view) {
                ButterKnife.bind(this, view);
            }
        }
    }
}
